package com.example.takeaway.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.takeaway.common.ResponseEnum;
import com.example.takeaway.context.UserInfoContext;
import com.example.takeaway.converter.ShopConverter;
import com.example.takeaway.exception.BusException;
import com.example.takeaway.mapper.ShopMapper;
import com.example.takeaway.model.bo.Shop;
import com.example.takeaway.model.vo.ShopVO;
import com.example.takeaway.service.ShopService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 店铺表 服务实现类
 * </p>
 *
 * @author 邢晨旭
 * @since 2023-10-12
 */
@Service
public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements ShopService {

    @Resource
    ShopConverter shopConverter;

    @Override
    public ShopVO getShopInfo() {
        Long shopId = UserInfoContext.get().getUserId();
        Shop shop = baseMapper.selectById(shopId);
        if (shop == null || shop.getIsDeleted() == 1) {
            throw new BusException(ResponseEnum.SHOP_NOT_EXIST);
        }
        return shopConverter.toShopVO(shop);
    }
}
